package com.lhd.weibo.service.impl;

import com.lhd.weibo.mapper.WeiboMapper;
import com.lhd.weibo.pojo.dto.WeiboDTO;
import com.lhd.weibo.pojo.entity.Weibo;
import com.lhd.weibo.pojo.vo.WeiboDetailVO;
import com.lhd.weibo.pojo.vo.WeiboIndexVO;
import com.lhd.weibo.service.WeiboService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author lhd
 * date 2024/5/16
 * @apiNote
 */
@Service
@Slf4j
public class WeiboServiceimpl implements WeiboService {

    @Autowired
    private WeiboMapper weiboMapper;
    @Override
    public int addWeibo(WeiboDTO weiboDTO) {
        log.info("WeiboDTO:{}", weiboDTO);

        Weibo weibo = new Weibo();
        BeanUtils.copyProperties(weiboDTO, weibo);
        weibo.setCreated(new Date());
        //调用数据库插入微博数据
        return weiboMapper.insert(weibo);
    }

    @Override
    public List<WeiboIndexVO> listForIndex() {
        return weiboMapper.list();
    }

    @Override
    public List<WeiboIndexVO> listForIndexByUserId(Long id) {
        return weiboMapper.listForIndexByUserId(id);
    }

    @Override
    public void deleteById(Long id) {
        weiboMapper.deleteById(id);
    }

    @Override
    public WeiboDetailVO detailById(Long id) {
        return weiboMapper.detailById(id);
    }
}
